<?php
$host = "http://localhost:8080";
$pos = strrpos($host, ':');
echo 'pos: ' . $pos . ' ';
if ($pos !== false) {
    $port = (int) substr($host, $pos + 1);
    echo 'port: ' . $port . '   ';
    echo '---' . strpos($host, 'http');
    if (strpos($host, 'http') !== false || strpos($host, 'https') !== false) {
        $host = substr($host, 0, $pos);
        echo 'host: ' . $host . '   ';
    } else {
        $host = strstr($host, ':', true);
    }
}

echo $host;